/**
 * 解决ios光标出现在header之上的问题，添加指令到 ion-cotent
 * example:
 * <ion-content fix-cursor>
 *     ...
 * </ion-content>
 */
import {Directive, HostListener} from "@angular/core";

@Directive({
    selector: '[fix-cursor]'
})
export class FixCursorDirectives {

    @HostListener('touchmove', ['$event.target'])
    onTouchstart() {
        this.eventHandle();
    }

    constructor() {
        console.log('d');
    }

    eventHandle() {
        if (document.hasFocus() && document.activeElement.tagName.toUpperCase() === 'INPUT'
            || document.hasFocus() && document.activeElement.tagName.toUpperCase() === 'TEXTAREA') {
            let input = <HTMLInputElement> document.activeElement;
            input.blur();
        }
    }
}
